#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define size 10
void reverse(int* left, int* right)
{
    while (left < right)
    {
        int tmp = *left;
        *left = *right;
        *right = tmp;
        left++;
        right--;
    }
}
void rotate1(int* nums, int numsSize, int k)
{
    if (k > numsSize)
    {
        k %= numsSize;
    }
    reverse(nums, nums + numsSize - k - 1);
    reverse(nums + numsSize - k, nums + numsSize - 1);
    reverse(nums, nums + numsSize - 1);
}

void rotate(int* nums, int numsSize, int k)
{
    if (k > numsSize)
    {
        k %= numsSize;
    }
    int* tmp = (int*)malloc(sizeof(int) * numsSize);
    memcpy(tmp, nums+ numsSize - k, k*sizeof(int));
    memcpy(tmp + k, nums, (numsSize - k) * sizeof(int));
    memcpy(nums, tmp, numsSize * sizeof(int));
    free(tmp);
    tmp = NULL;
}


int main()
{
    int arr[] = { 0,1,2,3,4,5 }; 
    int len = sizeof(arr) / sizeof(arr[0]);
    rotate(arr, len, 3);
    for (int i = 0; i < len; i++)
    {
        printf("%d ", arr[i]);
    }
    return 0;
}